package com.nf.health.app.inquiry.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.nf.health.app.R;
import com.nf.health.app.inquiry.bean.DoctorDetailBean;
import com.nf.health.app.inquiry.impl.bindviewhl.DocType;
import com.nf.health.app.inquiry.impl.viewholder.DoctorCommentHeaderViewHolder;
import com.nf.health.app.inquiry.impl.viewholder.DoctorCommentViewHolder;
import com.nf.health.app.inquiry.impl.viewholder.DoctorFunctionViewHolder;
import com.nf.health.app.inquiry.impl.viewholder.DoctorHeaderViewHolder;
import com.nf.health.app.inquiry.impl.viewholder.DoctorIngerRogationViewLLHolder;
import com.nf.health.app.models.DoctorCommnetVo;
import com.nf.health.app.models.DoctorServiceSettingModel;
import com.nf.health.app.widget.OnMyOnClistener;
import com.nf.health.app.widget.OnMyOnClistener2;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Jason on 2016/9/20.
 * 医生主界面 医生详情
 */
public class DocDetailRecycleAdapter extends RecyclerView.Adapter implements View.OnClickListener{
    private int CPOUNT_ITEM_NUM = 0;
    private LayoutInflater inflater;
    private Activity cnt ;
    private int commentlistSize = 0  ;
    private OnMyOnClistener onMyOnClistener;//注册点击事件
    private OnMyOnClistener2 onMyOnClistener2;//注册点击事件

    public DoctorDetailBean docDetail;//获取医生详情基本信息
    public List<DoctorCommnetVo> doctorCommnetVoList;//获取医生的将健康评价
    public List<DoctorServiceSettingModel> doctorServiceSettingModelList;//功能购买服务的展示

    private  List<HashMap<String,String>> HworkTimeList;//所选择的出诊时间集合
    private String REGISTRATIONSTATE = "";
    public DocDetailRecycleAdapter(Activity cnt, Object ss){
        inflater =LayoutInflater.from(cnt);
        this.cnt = cnt;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if(viewType == DocType.TYPE_HEADER.getType()){
            View viewAds = inflater.inflate(R.layout.view_doctor_headerview, null);// 医生基本详情 头像，简介
            return new DoctorHeaderViewHolder(viewAds,cnt,onMyOnClistener2);
        }else if(viewType == DocType.TYPE_FUNCTION.getType()){
            View viewAds = inflater.inflate(R.layout.view_doctor_func, null);// 医生基本详情 功能展示
            return new DoctorFunctionViewHolder(viewAds,cnt);
        }else if(viewType == DocType.TYPE_INTERROGATION_DOC.getType()){
            View viewAds = inflater.inflate(R.layout.ll_view_interrogation, null);// 出诊时间
            return new DoctorIngerRogationViewLLHolder(viewAds,cnt.getBaseContext());
        }else if(viewType == DocType.TYPE_DISCUSS_COM_HEAD.getType()){
            View viewAds = inflater.inflate(R.layout.view_comment_head, null);//4头部局
            return new DoctorCommentHeaderViewHolder(viewAds,onMyOnClistener);
        }else if(viewType == DocType.TYPE_DISCUSS_COM_LIST.getType()){
            View viewAds = inflater.inflate(R.layout.view_comment_list, null);//评论列表
            return new DoctorCommentViewHolder(viewAds,cnt.getBaseContext(),inflater);
        }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if(holder instanceof DoctorHeaderViewHolder){// 医生基本详情 头像，简介
            DoctorHeaderViewHolder doctorHeaderViewHolder = (DoctorHeaderViewHolder) holder;
            doctorHeaderViewHolder.loadData(docDetail);
        }else  if(holder instanceof DoctorFunctionViewHolder){// 医生基本详情 功能展示
            DoctorFunctionViewHolder doctorFunctionViewHolder = (DoctorFunctionViewHolder) holder;
            doctorFunctionViewHolder.loadData(docDetail);
            doctorFunctionViewHolder.reFreshMyTvText(doctorServiceSettingModelList);
            doctorFunctionViewHolder.refreshMyGhaoTx(REGISTRATIONSTATE);
        }else  if(holder instanceof DoctorIngerRogationViewLLHolder){// 出诊时间
            DoctorIngerRogationViewLLHolder doctorIngerRogationViewLLHolder = (DoctorIngerRogationViewLLHolder) holder;
            doctorIngerRogationViewLLHolder.loadData(HworkTimeList);
        }else  if(holder instanceof DoctorCommentHeaderViewHolder){//评论头布局
            DoctorCommentHeaderViewHolder doctorCommentHeaderViewHolder = (DoctorCommentHeaderViewHolder) holder;
            doctorCommentHeaderViewHolder.reFreshMyTvText(commentlistSize);
        }else  if(holder instanceof DoctorCommentViewHolder){//评论列表
            DoctorCommentViewHolder doctorCommentViewHolder = (DoctorCommentViewHolder) holder;
            try {//防止空指针之类的异常
                if(doctorCommnetVoList != null && doctorCommnetVoList.size() > 0){
                    int i = CPOUNT_ITEM_NUM - position - 1;
                    DoctorCommnetVo doctorCommnetVo  = doctorCommnetVoList.get(i);
                    doctorCommentViewHolder.reFreshMyTvText(doctorCommnetVo);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }

    /**
     * 医生基本详情 头像，简介
     * @param docDetail
     */
    public void setMyHeaderDocDetail(DoctorDetailBean docDetail){
        this.docDetail = docDetail;
        notifyItemChanged(DocType.TYPE_HEADER.getType());
    }
    /**
     * 刷新功能（家庭服务，付费咨询，健康管理）
     * @param
     */
    public void setDocFunctionData(List<DoctorServiceSettingModel> doctorServiceSettingModelList){
        this.doctorServiceSettingModelList = doctorServiceSettingModelList;
        notifyItemChanged(DocType.TYPE_FUNCTION.getType());
    }
    /**
     * 刷新功能 医生的评价
     * @param
     */
    public void setDoctorCommentData(List<DoctorCommnetVo> doctorCommnetVoList){
        this.doctorCommnetVoList =doctorCommnetVoList;
        notifyItemChanged(DocType.TYPE_DISCUSS_COM_LIST.getType());
    }

    /**
     * 刷新评论列  表头布局
     * @param
     */
    public void setHeadCommentHead(int commentlistSize){
        this.commentlistSize =commentlistSize;
        notifyItemChanged(DocType.TYPE_DISCUSS_COM_HEAD.getType());
    }
    /**
     * //所选择的出诊时间集合
     * @param
     */
    public void seHworkTimeList(List<HashMap<String,String>> HworkTimeList){
        this.HworkTimeList =HworkTimeList;
        notifyItemChanged(DocType.TYPE_INTERROGATION_DOC.getType());
    }

    /**
     * 刷新 挂号记录
     * @param
     */
    public void setlRegistrationState(String REGISTRATIONSTATE){
        this.REGISTRATIONSTATE =REGISTRATIONSTATE;
        notifyItemChanged(DocType.TYPE_FUNCTION.getType());
    }


    @Override
    public int getItemCount() {
        CPOUNT_ITEM_NUM = 4;
        if(doctorCommnetVoList != null){
            CPOUNT_ITEM_NUM = CPOUNT_ITEM_NUM + doctorCommnetVoList.size();
        }
        return CPOUNT_ITEM_NUM;
    }
    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return  DocType.TYPE_HEADER.getType();
        } else if (position == 1) {
            return  DocType.TYPE_FUNCTION.getType();
        } else if (position == 2) {
            return DocType.TYPE_INTERROGATION_DOC.getType();
        } else if(position == 3){// if(position == 3)
            return DocType.TYPE_DISCUSS_COM_HEAD.getType();
        } else {
            return DocType.TYPE_DISCUSS_COM_LIST.getType();
        }
    }
    @Override
    public void onClick(View v) {

    }


    public void regisitOnClickListener(OnMyOnClistener onMyOnClistener){
        this.onMyOnClistener = onMyOnClistener;
    }
    public void regisitOnMyOnClistener2(OnMyOnClistener2 onMyOnClistener2){
        this.onMyOnClistener2 = onMyOnClistener2;
    }

}
